package action;
import Impl.TopicDaoImpl;
import Impl.plateDaoImpl;
import dao.TopicDao;
import entity.Plate;
import entity.TopicInfo;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sound.midi.Soundbank;
import java.io.IOException;

@WebServlet(name = "SendTopicAction")
public class SendTopicAction extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        TopicDao topicDao = new TopicDaoImpl();
        System.out.println("----------正在执行sendTopic-----------");
        request.setCharacterEncoding("utf-8");
//        帖子标题
        String send_title = request.getParameter("send_title");
        System.out.println(send_title);
//        帖子内容
        String send_content = request.getParameter("send_content");
        System.out.println(send_content);
//       获取子版块的ID
        Integer child_sid = Integer.parseInt(request.getParameter("child_block"));
        int father_sid = Integer.parseInt(request.getParameter("father_block"));
        System.out.println("父板块的ID："+father_sid);
        User user= (User) request.getSession().getAttribute("user");
        int uid = user.getUid();
        System.out.println(uid);
        topicDao.insertTopicInfo(send_title,send_content,child_sid,uid);
        new TopicDaoImpl().getTopicCountById(child_sid);
        new plateDaoImpl().updateTopicCounts(father_sid);
        request.getRequestDispatcher("showblock.jhtml").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
